import Vue from 'vue'
import Layout from '@/layout'
import Router from 'vue-router'
Vue.use(Router)
const originalPush = Router.prototype.push
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}

export const constantRoutes = [{
  path: '/',
  redirect: '/login'
}, // 重定向,指向了home组件
// 基础数据管理
{
  path: '/basedata',
  component: Layout,
  redirect: '/basedata/brand',
  name: 'basedata',
  userType: 1,
  meta: { title: '基础数据管理', icon: 'tree' },
  children: [
    {
      path: 'brand',
      name: 'brand',
      component: () =>
                    import ('@/views/itemcenter/basedata/brand/brand_list'),
      meta: { title: '品牌管理', icon: 'list', keepAlive: false }
    }, {
      path: 'categroy',
      name: 'categroy',
      component: () =>
                    import ('@/views/itemcenter/basedata/categroy/categroy_list'),
      meta: { title: '分类管理', icon: 'list', keepAlive: false }
    }, {
      path: 'store',
      name: 'store',
      component: () =>
                    import ('@/views/itemcenter/basedata/store/store_list'),
      meta: { title: '门店管理', icon: 'list', keepAlive: false }
    }/*, {
                path: 'shopcategory',
                name: "shopcategory",
                component: () =>
                    import ('@/views/itemcenter/basedata/shopcategory/shopcategory_list'),
                meta: { title: '店内分类管理', icon: 'list' ,keepAlive: false},
            }*/
  ]
},
{
  path: '/login',
  component: () =>
            import ('../views/login/index'),
  hidden: true
},
{
  path: '/404',
  component: () =>
            import ('@/views/error-page/404'),
  hidden: true
},
{
  path: '/401',
  component: () =>
            import ('@/views/error-page/401'),
  hidden: true
},

{ // 商品管理
  path: '/item',
  component: Layout,
  name: 'Item',
  meta: { title: '商品管理', icon: 'tree' },
  children: [
    {
      path: 'item',
      name: 'Item',
      type: 1,
      glotype: false,
      component: () =>
                    import ('@/views/itemcenter/item/item/item_list'),
      meta: { title: '商品管理', icon: 'list', keepAlive: false }
    },
    { // 新增普通商品
      path: 'itemAdd',
      name: 'ItemAdd',
      component: () =>
                    import ('@/views/itemcenter/item/item/add/item_create'),
      hidden: true
    },
    { // 修改普通商品
      path: 'itemUpdate',
      name: 'ItemUpdate',
      component: () =>
                    import ('@/views/itemcenter/item/item/update/item_update'),
      hidden: true
    }, { // 普通商品--详情
      path: 'itemDetail',
      name: 'ItemDetail',
      component: () =>
                    import ('@/views/itemcenter/item/item/detail/item_detail'),
      meta: { title: '查看普通商品详情' },
      hidden: true
    }, {
      path: 'storeitem',
      name: 'storeitem',
      type: 1,
      glotype: false,
      component: () =>
                    import ('@/views/itemcenter/item/storeitem/storeItem_list'),
      meta: { title: '门店商品', icon: 'list', keepAlive: false }
    }
  ]
},
{// 轮播图管理

  path: '/carouselManagement',
  component: Layout,
  redirect: '/carouselManagement/CarouselList',
  name: 'carouselManagement',
  userType: 1,
  meta: { title: '轮播图管理', icon: 'tree' },
  alwaysShow: true,
  children: [
    {
      path: 'CarouselList',
      name: 'CarouselList',
      type: 1,
      glotype: false,
      component: () =>
                    import ('@/views/itemcenter/item/carouselManagement/CarouselList'),
      meta: { title: '轮播图列表', icon: 'list', keepAlive: false }
    }
  ]

},
{ // 订单管理
  path: '/order',
  component: Layout,
  redirect: '/order/orderList',
  name: 'Order',
  userType: 1,
  meta: { title: '订单管理', icon: 'tree' },
  alwaysShow: true,
  children: [
    {
      path: 'OrderList',
      name: 'OrderList',
      component: () =>
                    import ('@/views/itemcenter/item/order/order_list'),
      meta: { title: '订单列表', icon: 'list', keepAlive: false }
    }, {
      path: 'RefundApplyList',
      name: 'RefundApplyList',
      component: () =>
                    import ('@/views/itemcenter/item/order/refund_apply_list'),
      meta: { title: '退款申请', icon: 'list', keepAlive: false }
    }, {
      path: 'RefundOrderList',
      name: 'RefundOrderList',
      component: () =>
                    import ('@/views/itemcenter/item/order/refund_order_list'),
      meta: { title: '退款订单', icon: 'list', keepAlive: false }
    }, {
      path: 'OrderPayRecordList',
      name: 'OrderPayRecordList',
      component: () =>
                    import ('@/views/itemcenter/item/order/order_pay_record_list'),
      meta: { title: '支付记录', icon: 'list', keepAlive: false }
    }
  ]
},
{ // 素材管理
  path: '/video',
  component: Layout,
  redirect: '/video/videoList',
  name: 'Video',
  userType: 1,
  meta: { title: '素材管理', icon: 'tree' },
  alwaysShow: true,
  children: [{
    path: 'videoList',
    name: 'VideoList',
    component: () =>
                import ('@/views/itemcenter/matter/video/video_list'),
    meta: { title: '视频管理', icon: 'list', keepAlive: false }
  }]
}/*,
    {
        path: '/systemSettings',
        component: Layout,
        userType:0,
        meta: {
            title: '系统管理',
            icon: 'tree'
        },
        redirect: '/systemSettings/congigMent',
        name: "systemSettings",
        // role:'vn0sy5z',
        alwaysShow: true,
        children: [
            {
                path: 'congigMent',
                component: () =>
                    import('@/views/systemSettings/congigMent'),
                name: 'congigMentList',
                meta: {title: '配置管理', icon: 'list' ,keepAlive: false }
            },
            {
                path: 'enableTaskList',
                name: "enableTaskList",
                component: () =>
                    import ('@/views/itemcenter/task/enableTask/enable_task_list'),
                meta: { title: '任务启停', icon: 'list' ,keepAlive: false},
            }
        ]
      }*/
]
const asyncRoutes = [
  { path: '*', redirect: '/404', hidden: true }
]
const createRouter = () => {
  return new Router({
    mode: 'history',
    routes: constantRoutes,
    scrollBehavior: () => ({ y: 0 }),
    base: process.env.VUE_APP_BASE_ROUTER_NAME
  })
}

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}
export default router
export { asyncRoutes }

